<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Books extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();

    }

    public function index()
    {
         $list = \app\common\model\Agent::field('agent_name,agent_region,agent_phone')->select();
        $list = collection($list)->toArray();
        $tf2020 = Db::connect([
            // 数据库类型
            'type'        => 'mysql',
            // 数据库连接DSN配置
            'dsn'         => '',
            // 服务器地址
            'hostname'    => '42.96.177.38',
            // 数据库名
            'database'    => 'tf2020',
            // 数据库用户名
            'username'    => 'wangmeng',
            // 数据库密码
            'password'    => 'wangmeng',
            // 数据库连接端口
            'hostport'    => '',
            // 数据库连接参数
            'params'      => [],
            // 数据库编码默认采用utf8
            'charset'     => 'utf8',
            // 数据库表前缀
            'prefix'      => 'tf_',
        ]);

        echo "<pre>";
         foreach ($list as $value)
         {

             $userid = $tf2020->table('tf_admin')->field('userid')->where('username',$value['agent_phone'])->find();
             $str = substr($value['agent_region'],0,6);
             echo "update tf_books set fahuo='{$value['agent_region']}',kaoshi='{$str}' where product=35 and dealer_uid={$userid['userid']};</br>";
         }
    }

}
